package gaej.example.contact.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class ComponistDelegate {
    private MusicServiceAsync musicService = GWT.create(MusicService.class);
    ComponistGUI gui;
    
    void listComponisten() {
        musicService.listComponisten(new AsyncCallback<List<Componist>> () {
                    public void onFailure(Throwable caught) {
                        gui.service_eventListComponistenFailed(caught);
                    }
        
                    public void onSuccess(List<Componist> result) {
                        gui.service_eventListRetrievedFromService(result);
                        
                    }
        }//end of inner class
        );//end of listComponists method call.
    }
    
    void addComponist(final Componist componist) {
        musicService.addComponist(componist, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventAddComponistFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventAddComponistSuccessful();
            }
        }//end of inner class
        );//end of addComponist method call.        
    }

    void updateComponist(final Componist componist) {
        musicService.updateComponist(componist, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventUpdateComponistFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventUpdateSuccessful();
            }
        }//end of inner class
        );//end of updateComponist method call.        
    }

    void removeComponist(final Componist componist) {
        musicService.removeComponist(componist, new AsyncCallback<Void> () {
            public void onFailure(Throwable caught) {
                gui.service_eventRemoveComponistFailed(caught);
            }

            public void onSuccess(Void result) {
                gui.service_eventRemoveComponistSuccessful();
            }
        }//end of inner class
        );//end of updateComponist method call.        
    }
    
}
